using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_resumes : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "Database2000"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                Session["ResumeStatus"] = "Update";
                ShowResume();
            }
        }
    }

    protected void btnNew_Click(object sender, EventArgs e)
    {
        Session["ResumeStatus"] = "New";
        Response.Redirect("resume.aspx");
    }
    
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        DeleteResume();
        ShowResume();
    }
    void ShowResume()
    {
        SqlServerProvider cls = new SqlServerProvider(connectionString);
        cls.CommandText = "select ResumeID, ResumeTitle " +
        ", ContactEmail, convert(char(11), LastUpdateDate,103) as LastUpdateDate  from tblJSResumes" +
        " where UserID=@UserID";
        cls.ParameterCollection = new string[1]{"@UserID"};
        cls.ValueCollection = new string[1]{Convert.ToString(
        Session.Contents["jsuserid"])};                  
        DataTable dataTable = cls.GetDataTable( );
        GridView1.DataSource = dataTable;
        GridView1.DataBind();
    }
    void DeleteResume()
    {
        string resumeID = "";
        foreach (GridViewRow item in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)item.Cells[0].FindControl("chkResumeID");
            if (checkBox.Checked)
                resumeID += item.Cells[0].Text + ",";
        }
        if (resumeID != "")
        {
            SqlServerProvider cls = new SqlServerProvider(connectionString);
            cls.CommandText = "delete  from tblJSResumes" +
            " where UserID='" + Convert.ToString(
            Session.Contents["jsuserid"])
            + "' and resumeID in('" +
            resumeID.Replace(",", "','") + "')";
            cls.ExecuteNonQuery( );
        }
    }
}
